package com.sau.pixelcart.mapper;

import com.sau.pixelcart.domain.entity.ProductInventory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 商品实时库存表 Mapper 接口
 * </p>
 *
 * @author Inton
 * @since 2025-03-08
 */

@Mapper
public interface ProductInventoryMapper extends BaseMapper<ProductInventory> {

    /**
     * 修改商品库存
     * @param productInventoryList
     */
    void updateBatch(@Param("productInventoryList") List<ProductInventory> productInventoryList);

    /**
     * 删除商品对应库存信息
     * @param productId
     */
    @Delete("delete from product_inventory where product_id = #{productId}")
    void deleteByProductId(@Param("productId") String productId);

    /**
     * 扣减库存
     * @param id
     * @param stock
     * @param aLong
     * @return
     */
    int deductStock(@Param("id") String id, @Param("stock") Integer stock, @Param("version") Long version);
}
